| Conditions | 7 |
| Total Lines | 87 |
| Code Lines | 71 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 0 | ||
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
| 1 | import { stopLocationUpdatesAsync } from "expo-location"; |
||
| 7 | |||
| 8 | export default function ScooterModal({navigation, scooter, modalVisible, setModalVisible, currentCity}) { |
||
| 9 | const [scooterName, setScooterName] = useState(null); |
||
| 10 | const [scooterId, setScooterId] = useState(null); |
||
| 11 | const [battery, setBattery] = useState(null); |
||
| 12 | const [fixedRate, setFixedRate] = useState(null); |
||
| 13 | const [timeRate, setTimeRate] = useState(null); |
||
| 14 | |||
| 15 | |||
| 16 | const batteryImages = { |
||
| 17 | '100': require('../assets/battery_100.png'), |
||
| 18 | '75': require('../assets/battery_75.png'), |
||
| 19 | '50': require('../assets/battery_50.png'), |
||
| 20 | '25': require('../assets/battery_25.png') |
||
| 21 | } |
||
| 22 | |||
| 23 | function getBattery(batteryPercentage) { |
||
| 24 | if (batteryPercentage >= 75) { |
||
| 25 | return '100' |
||
| 26 | } else if (batteryPercentage >= 50) { |
||
| 27 | return '75' |
||
| 28 | } else if (batteryPercentage >= 25) { |
||
| 29 | return '50' |
||
| 30 | } else { |
||
| 31 | return '25' |
||
| 32 | } |
||
| 33 | }; |
||
| 34 | |||
| 35 | useEffect(() => { |
||
| 36 | function getScooterInfo(): void { |
||
| 37 | if (scooter) { |
||
| 38 | const title = scooter['name'].split('#'); |
||
| 39 | setScooterName(title[0]); |
||
| 40 | setScooterId(title[1]); |
||
| 41 | setBattery(getBattery(scooter['battery'])); |
||
| 42 | |||
| 43 | setFixedRate(currentCity['taxRates']['fixedRate']); |
||
| 44 | setTimeRate(currentCity['taxRates']['timeRate']); |
||
| 45 | // console.log(currentCity['taxRates']); |
||
| 46 | |||
| 47 | } |
||
| 48 | } |
||
| 49 | getScooterInfo(); |
||
| 50 | }); |
||
| 51 | |||
| 52 | |||
| 53 | // console.log(scooter); |
||
| 54 | |||
| 55 | return ( |
||
| 56 | <GestureRecognizer |
||
| 57 | style={{flex: 1}} |
||
| 58 | onSwipeDown={ () => setModalVisible(false) } |
||
| 59 | > |
||
| 60 | <Modal |
||
| 61 | animationType="slide" |
||
| 62 | transparent={true} |
||
| 63 | visible={modalVisible} |
||
| 64 | onRequestClose={() => { |
||
| 65 | setModalVisible(!modalVisible) |
||
| 66 | }} |
||
| 67 | |||
| 68 | > |
||
| 69 | <View style={styles.modalContainer}></View> |
||
| 70 | |||
| 71 | |||
| 72 | <View style={styles.modalMessage}> |
||
| 73 | <View style={styles.swipeButton}></View> |
||
| 74 | |||
| 75 | <View style={styles.titleContainer}> |
||
| 76 | <Image style={styles.scooterImage} source={require('../assets/scooter2.png')}></Image> |
||
| 77 | |||
| 78 | <View style={styles.textContainer}> |
||
| 79 | <Text style={styles.scooterTitle}> {scooterName} {scooterId}</Text> |
||
| 80 | <Image style={styles.battery} source={batteryImages[`${battery}`]}></Image> |
||
| 81 | </View> |
||
| 82 | |||
| 83 | </View> |
||
| 84 | |||
| 85 | <Pressable style={styles.tourButton} > |
||
| 86 | <Text style={{color: 'white'}}>Start tour</Text> |
||
| 87 | </Pressable> |
||
| 88 | |||
| 89 | <Text style={{color: 'grey'}}> {fixedRate} kr unlocking + {timeRate} kr / min. </Text> |
||
| 90 | |||
| 91 | </View> |
||
| 92 | </Modal> |
||
| 93 | </GestureRecognizer> |
||
| 94 | ) |
||
| 165 | }) |